package com.xiaoshuidi.cloud.module.rooms.controller.admin.roomEquipmentrepair;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomEquipmentrepair.vo.RoomEquipmentRepairResp;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomEquipmentrepair.vo.RoomEquipmentRepairVO;
import com.xiaoshuidi.cloud.module.rooms.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.rooms.service.RoomEquipmentRepairService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 资产报修")
@RestController
@RequestMapping(ApiConstants.NAME + "/equipment-repair")
@RequiredArgsConstructor
public class RoomEquipmentRepairController {
    private final RoomEquipmentRepairService roomEquipmentRepairService;


    @Operation(summary = "创建资产维修记录")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:repair:create')")
    public CommonResult<Boolean> create(@RequestBody RoomEquipmentRepairVO vo) {
        return success(roomEquipmentRepairService.create(vo));
    }


    @Operation(summary = "查询资产维修记录")
    @GetMapping("/list")
    @Parameter(name = "equipmentId", description = "ID")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:repair:query')")
    public CommonResult<List<RoomEquipmentRepairResp>> list(Long equipmentId) {
        return success(roomEquipmentRepairService.listByEquipmentId(equipmentId));
    }

    @Operation(summary = "分页查询维修记录")
    @GetMapping("/page")
    @Parameters({
            @Parameter(name = "equipmentId", description = "ID"),
            @Parameter(name = "pageNum", description = "页码"),
            @Parameter(name = "pageSize", description = "每页大小"),
    })
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:repair:query')")
    public CommonResult<PageResult<RoomEquipmentRepairResp>> page(Long equipmentId, int pageNum, int pageSize) {
        return success(roomEquipmentRepairService.page(equipmentId, pageNum, pageSize));
    }


    @Operation(summary = "查询维修记录详情")
    @GetMapping("/get-by-id")
    @Parameter(name = "id", description = "ID")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:repair:query')")
    public CommonResult<RoomEquipmentRepairVO> getById(Long id) {
        return success(roomEquipmentRepairService.getById(id));
    }


    @Operation(summary = "删除维修记录")
    @DeleteMapping("/delete-by-id")
    @Parameter(name = "id", description = "ID")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:repair:delete')")
    public CommonResult<Boolean> deleteById(Long id) {
        return success(roomEquipmentRepairService.deleteById(id));
    }

    @Operation(summary = "更改维修记录状态")
    @PutMapping("/updateState-by-id")
    @Parameter(name = "id", description = "ID")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:repair:update-state')")
    public CommonResult<Boolean> updateStateById(Long id) {
        return success(roomEquipmentRepairService.updateStateById(id));
    }

}
